package com.lqh.controller;

import com.lqh.annotation.LogFlag;
import com.lqh.pojo.Clazz;
import com.lqh.pojo.ClazzQueryParam;
import com.lqh.pojo.PageResult;
import com.lqh.pojo.Result;
import com.lqh.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping
    public Result pageQuery(ClazzQueryParam clazzQueryParam){
        log.info("查询返回班级信息{}",clazzQueryParam);
        PageResult<Clazz> pageResult = clazzService.pqgeQuery(clazzQueryParam);
        return Result.success(pageResult);
    }
    @LogFlag
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除班级信息{}",id);
        clazzService.deleteById(id);
        return Result.success();
    }
    @LogFlag
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){
        log.info("添加班级信息{}",clazz);
        clazzService.addClazz(clazz);
        return Result.success();
    }
    //这是在编辑的时候查询回显用的
    @GetMapping("/{id}")
    public Result searchById(@PathVariable Integer id){
        log.info("查询班级信息{}",id);
        Clazz clazz = clazzService.searchById(id);
        return Result.success(clazz);
    }
    @LogFlag
    @PutMapping
    public Result updateClazz(@RequestBody Clazz clazz){
        log.info("修改班级信息{}",clazz);
        clazzService.updateClazz(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result clazzList(){
        log.info("查询所有班级信息");
        return Result.success(clazzService.list());
    }

}
